import { Component, OnInit } from '@angular/core';
import { BladeContainerBase } from "../../../../../shared/blade/blade-container-base";
import { Scheme } from "../../../../../entity/scheme.model";
import { CompanyService } from "app/service/company.service";
import { Command } from "app/shared/toolbar.service";
import { FormBuilder, Validators, FormControl } from "@angular/forms";
import { UploadService } from "../../../../../service/upload.service";
@Component({
  selector: 'app-upload',
  templateUrl: './upload.component.html',
  styleUrls: ['./upload.component.css']
})
export class UploadComponent extends BladeContainerBase<Scheme>{
  file: File;
  constructor(
    private fb: FormBuilder,
    private companyService: CompanyService,
    private uploadService: UploadService
  ) {
    super(fb);
  }

  ngOnInit(): void {
    this.commands = [
      // new Command("save", "保存", "fa fa-save", "setofkey:update", (blade) => this.exeSaveChange(blade), (blade) => this.canSaveChange(blade)),
    ]
    super.ngOnInit();
  }

  // exeSaveChange(blade: any): void {
  //   this.save();
  // }
  // canSaveChange(blade: any): boolean {
  //   return this.file != null;
  // }

  save() {
    this.uploadService.upFile(this.file,this.parentEntity.current.schemeId,this.parentEntity.current.multipleValue)
      .then(res => {
          (this.parentBlade.bladeContainerInstance).refresh(this.parentEntity.current);
          this.bladeService.closeBlade(this.currentBlade);
          return true;       
      })
  }
  

  onUpload(ev) {
    this.file = ev.files;
    this.save();

  }
  onRemove(ev) {
    this.file = null;
  }


}





// WEBPACK FOOTER //
// ./src/app/module/basic/model/fault-alarm/upload/upload.component.ts